<template>
    <div class="container">
        <h3>库存管理</h3>
        <el-tabs v-model="activeName" type="border-card" style="margin-top:20px;" @tab-click="handleClick">
                <el-tab-pane v-if='switchHeadTab == "生产系统" || switchHeadTab == "中药饮片"' label="中药材" name="中药材">
                    <el-row style="margin: 10px 0 20px 0">
                        <el-col :span="7">
                            <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="searchName1">
                                <i slot="prefix" class="el-input__icon el-icon-search"></i>
                                <el-button slot="append" @click="handleSearch1">搜索</el-button>
                            </el-input>
                        </el-col>
                        <router-link :to="{path:'/inventory/invenToryIndex'}" v-if="check"><el-button type="primary" style="float:right; margin-right: 10px">仓库管理</el-button></router-link>
                        <el-button style="float:right; margin-right: 10px" @click="download">导出</el-button>
                    </el-row>
                    <el-row>
                        <el-table
                            :data="tableData"
                            border
                            ref="multipleTable"
                            header-cell-class-name="table-header">
                            <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                            <el-table-column prop="batch" sortable label="批次"></el-table-column>
                            <el-table-column prop="totalNum" sortable label="数量">
                                <template slot-scope="scope">
                                    {{scope.row.totalNum}}<span v-if="scope.row.totalNum != '' && scope.row.totalNum != null">{{scope.row.units}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="type" sortable label="入库类型">
                                <template slot-scope="scope">
                                    {{scope.row.type}}入库
                                </template>
                            </el-table-column>
                            <el-table-column prop="surplusNum" sortable label="剩余数量">
                                <template slot-scope="scope">
                                    {{scope.row.surplusNum}}{{scope.row.units}}
                                </template>
                            </el-table-column>
                            <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
                            <el-table-column label="操作" width="150" align="center">
                                <template slot-scope="scope">
                                    <el-button
                                        type="text"
                                        @click="handleView(scope.$index, scope.row)"
                                    >查看</el-button>
                                    <span v-if="scope.row.isRecall == 0">
                                <span v-if="check1">
                                <el-button
                                    type="text"
                                    @click="handleFrmLoss(scope.$index, scope.row)"
                                    v-if="scope.row.type == '原料'"
                                >报损</el-button>
                                <el-button
                                    type="text"
                                    @click="handleNum(scope.$index, scope.row)"
                                    v-if="scope.row.type == '生产'"
                                >调整产量</el-button>
                                </span>
                                </span>
                                    <el-button
                                        v-if="scope.row.isRecall == 1"
                                        type="info"
                                        disabled
                                    >已召回</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize1" @current-change="handleCurrentChange1" :total="total1" :current-page.sync="currentPage1" style="margin-top:20px"></el-pagination>
                    </el-row>
                </el-tab-pane>
                <el-tab-pane v-if='switchHeadTab == "生产系统" || switchHeadTab == "中药饮片"' label="辅料" name="辅料">
                    <el-row style="margin: 10px 0 20px 0">
                        <el-col :span="7">
                            <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="searchName2">
                                <i slot="prefix" class="el-input__icon el-icon-search"></i>
                                <el-button slot="append" @click="handleSearch2">搜索</el-button>
                            </el-input>
                        </el-col>
                        <router-link :to="{path:'/inventory/invenToryIndex'}"><el-button type="primary" v-if="check" style="float:right; margin-right: 10px">仓库管理</el-button></router-link>
                        <el-button style="float:right; margin-right: 10px" @click="download">导出</el-button>
                    </el-row>
                    <el-row>
                        <el-table
                            :data="tableData"
                            border
                            ref="multipleTable"
                            header-cell-class-name="table-header"
                        >
                            <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                            <el-table-column prop="batch" sortable label="批次"></el-table-column>
                            <el-table-column prop="totalNum" sortable label="数量">
                                <template slot-scope="scope">
                                    {{scope.row.totalNum}}<span v-if="scope.row.totalNum != '' && scope.row.totalNum != null">{{scope.row.units}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="type" sortable label="入库类型">
                                <template slot-scope="scope">
                                    {{scope.row.type}}入库
                                </template>
                            </el-table-column>
                            <el-table-column prop="surplusNum" sortable label="剩余数量">
                                <template slot-scope="scope">
                                    {{scope.row.surplusNum}}{{scope.row.units}}
                                </template>
                            </el-table-column>
                            <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
                            <el-table-column label="操作" width="150" align="center">
                                <template slot-scope="scope">
                                    <el-button
                                        type="text"

                                        @click="handleView(scope.$index, scope.row)"
                                    >查看</el-button>
                                    <span v-if="scope.row.isRecall == 0">
                                <span v-if="check1">
                                <el-button
                                    type="text"
                                    @click="handleFrmLoss(scope.$index, scope.row)"
                                    v-if="scope.row.type == '原料'"
                                >报损</el-button>
                                <el-button
                                    type="text"
                                    @click="handleNum(scope.$index, scope.row)"
                                    v-if="scope.row.type == '生产'"
                                >调整产量</el-button>
                                </span>
                                </span>
                                    <el-button
                                        v-if="scope.row.isRecall == 1"
                                        type="info"
                                        disabled
                                    >已召回</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize2" @current-change="handleCurrentChange2" :total="total2" :current-page.sync="currentPage2" style="margin-top:20px"></el-pagination>
                    </el-row>
                </el-tab-pane>
                <el-tab-pane v-if='switchHeadTab == "中药饮片"' label="中药饮片(半成品)" name="中药饮片(半成品)">
                <el-row style="margin: 10px 0 20px 0">
                    <el-col :span="7">
                        <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="searchMedicalHerbSemiFormedProducts">
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                            <el-button slot="append" @click="getMedicalHerbSemiFormedProducts">搜索</el-button>
                        </el-input>
                    </el-col>
                    <router-link :to="{path:'/inventory/invenToryIndex'}"><el-button type="primary" v-if="check" style="float:right; margin-right: 10px">仓库管理</el-button></router-link>
                    <el-button style="float:right; margin-right: 10px" @click="download">导出</el-button>
                </el-row>
                <el-row>
                    <el-table
                        :data="tableDataOfMedicinalHerbSemiFormedProducts"
                        border
                        ref="multipleTable"
                        header-cell-class-name="table-header"
                    >
                        <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                        <el-table-column prop="batch" sortable label="批次"></el-table-column>
                        <el-table-column prop="totalNum" sortable label="数量">
                            <template slot-scope="scope">
                                {{scope.row.totalNum}}<span v-if="scope.row.totalNum != '' && scope.row.totalNum != null">{{scope.row.units}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="type" sortable label="入库类型">
                            <template slot-scope="scope">
                                {{scope.row.type}}入库
                            </template>
                        </el-table-column>
                        <el-table-column prop="surplusNum" sortable label="剩余数量">
                            <template slot-scope="scope">
                                {{scope.row.surplusNum}}{{scope.row.units}}
                            </template>
                        </el-table-column>
                        <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
                        <el-table-column label="操作" width="150" align="center">
                            <template slot-scope="scope">
                                <el-button
                                    type="text"

                                    @click="handleView(scope.$index, scope.row)"
                                >查看</el-button>
                                <span v-if="scope.row.isRecall == 0">
                                <span v-if="check1">
                                <el-button
                                    type="text"
                                    @click="handleFrmLoss(scope.$index, scope.row)"
                                    v-if="scope.row.type == '原料'"
                                >报损</el-button>
                                <el-button
                                    type="text"
                                    @click="handleNum(scope.$index, scope.row)"
                                    v-if="scope.row.type == '生产'"
                                >调整产量</el-button>
                                </span>
                                </span>
                                <el-button
                                    v-if="scope.row.isRecall == 1"
                                    type="info"
                                    disabled
                                >已召回</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination layout="total, prev, pager, next, jumper" :page-size="medicalHerbPageSizeSemiFormedProducts" @current-change="(page)=>{medicalHerbPageSemiFormedProducts = page;getMedicalHerbSemiFormedProducts()}" :total="medicalHerbTotalSemiFormedProducts" :current-page.sync="medicalHerbPageSemiFormedProducts" style="margin-top:20px"></el-pagination>
                </el-row>
            </el-tab-pane>
                <el-tab-pane v-if='switchHeadTab == "中药饮片"' label="中药饮片" name="中药饮片">
                    <el-row style="margin: 10px 0 20px 0">
                        <el-col :span="7">
                            <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="searchMedicalHerb">
                                <i slot="prefix" class="el-input__icon el-icon-search"></i>
                                <el-button slot="append" @click="getMedicalHerb">搜索</el-button>
                            </el-input>
                        </el-col>
                        <router-link :to="{path:'/inventory/invenToryIndex'}"><el-button type="primary" v-if="check" style="float:right; margin-right: 10px">仓库管理</el-button></router-link>
                        <el-button style="float:right; margin-right: 10px" @click="download">导出</el-button>
                    </el-row>
                    <el-row>
                        <el-table
                            :data="tableDataOfMedicinalHerb"
                            border
                            ref="multipleTable"
                            header-cell-class-name="table-header"
                        >
                            <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                            <el-table-column prop="batch" sortable label="批次"></el-table-column>
                            <el-table-column prop="totalNum" sortable label="数量">
                                <template slot-scope="scope">
                                    {{scope.row.totalNum}}<span v-if="scope.row.totalNum != '' && scope.row.totalNum != null">{{scope.row.units}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="type" sortable label="入库类型">
                                <template slot-scope="scope">
                                    {{scope.row.type}}入库
                                </template>
                            </el-table-column>
                            <el-table-column prop="surplusNum" sortable label="剩余数量">
                                <template slot-scope="scope">
                                    {{scope.row.surplusNum}}{{scope.row.units}}
                                </template>
                            </el-table-column>
                            <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
                            <el-table-column label="操作" width="150" align="center">
                                <template slot-scope="scope">
                                    <el-button
                                        type="text"

                                        @click="handleView(scope.$index, scope.row)"
                                    >查看</el-button>
                                    <span v-if="scope.row.isRecall == 0">
                                <span v-if="check1">
                                <el-button
                                    type="text"
                                    @click="handleFrmLoss(scope.$index, scope.row)"
                                    v-if="scope.row.type == '原料'"
                                >报损</el-button>
                                <el-button
                                    type="text"
                                    @click="handleNum(scope.$index, scope.row)"
                                    v-if="scope.row.type == '生产'"
                                >调整产量</el-button>
                                </span>
                                </span>
                                    <el-button
                                        v-if="scope.row.isRecall == 1"
                                        type="info"
                                        disabled
                                    >已召回</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination layout="total, prev, pager, next, jumper" :page-size="medicalHerbPageSize" @current-change="(page)=>{medicalHerbPage = page;getMedicalHerb()}" :total="medicalHerbTotal" :current-page.sync="medicalHerbPage" style="margin-top:20px"></el-pagination>
                    </el-row>
                </el-tab-pane>
                <el-tab-pane v-if='switchHeadTab =="生产系统"' label="提取饮片" name="提取饮片">
                    <el-row style="margin: 10px 0 20px 0">
                        <el-col :span="7">
                            <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="searchName3">
                                <i slot="prefix" class="el-input__icon el-icon-search"></i>
                                <el-button slot="append" @click="handleSearch3">搜索</el-button>
                            </el-input>
                        </el-col>
                        <router-link :to="{path:'/inventory/invenToryIndex'}"><el-button type="primary" v-if="check" style="float:right; margin-right: 10px">仓库管理</el-button></router-link>
                        <el-button style="float:right; margin-right: 10px" @click="download">导出</el-button>
                    </el-row>
                    <el-row>
                        <el-table
                            :data="tableData"
                            border
                            ref="multipleTable"
                            header-cell-class-name="table-header"
                        >
                            <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                            <el-table-column prop="batch" sortable label="批次"></el-table-column>
                            <el-table-column prop="totalNum" sortable label="数量">
                                <template slot-scope="scope">
                                    {{scope.row.totalNum}}<span v-if="scope.row.totalNum != '' && scope.row.totalNum != null">{{scope.row.units}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="type" sortable label="入库类型">
                                <template slot-scope="scope">
                                    {{scope.row.type}}入库
                                </template>
                            </el-table-column>
                            <el-table-column prop="surplusNum" sortable label="剩余数量">
                                <template slot-scope="scope">
                                    {{scope.row.surplusNum}}{{scope.row.units}}
                                </template>
                            </el-table-column>
                            <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>

                            <el-table-column label="操作" width="150" align="center">
                                <template slot-scope="scope">
                                    <el-button
                                        type="text"

                                        @click="handleView(scope.$index, scope.row)"
                                    >查看</el-button>
                                    <span v-if="scope.row.isRecall == 0">
                                <span v-if="check1">
                                <el-button
                                    type="text"
                                    @click="handleFrmLoss(scope.$index, scope.row)"
                                    v-if="scope.row.type == '原料'"
                                >报损</el-button>
                                <el-button
                                    type="text"
                                    @click="handleNum(scope.$index, scope.row)"
                                    v-if="scope.row.type == '生产'"
                                >调整产量</el-button>
                                </span>
                                </span>
                                    <el-button
                                        v-if="scope.row.isRecall == 1"
                                        type="info"
                                        disabled
                                    >已召回</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize3" @current-change="handleCurrentChange3" :total="total3" :current-page.sync="currentPage3" style="margin-top:20px"></el-pagination>
                    </el-row>
                </el-tab-pane>
                <el-tab-pane v-if='switchHeadTab =="生产系统"' label="配方颗粒(浸膏粉)" name="配方颗粒(浸膏粉)">
                    <el-row style="margin: 10px 0 20px 0">
                        <el-col :span="7">
                            <el-input placeholder="请输入关键词" style="width:300px" v-model="searchName6">
                                <i slot="prefix" class="el-input__icon el-icon-search"></i>
                                <el-button slot="append" @click="handleSearch6">搜索</el-button>
                            </el-input>
                        </el-col>
                        <router-link :to="{path:'/inventory/invenToryIndex'}"><el-button type="primary" v-if="check" style="float:right; margin-right: 10px">仓库管理</el-button></router-link>
                        <el-button style="float:right; margin-right: 10px" @click="download">导出</el-button>
                    </el-row>
                    <el-row>
                        <el-table
                            :data="tableData"
                            border
                            ref="multipleTable"
                            header-cell-class-name="table-header"
                        >
                            <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                            <el-table-column prop="batch" sortable label="批次"></el-table-column>
                            <el-table-column prop="totalNum" sortable label="数量">
                                <template slot-scope="scope">
                                    {{scope.row.totalNum}}<span v-if="scope.row.totalNum != '' && scope.row.totalNum != null">{{scope.row.units}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="type" sortable label="入库类型">
                                <template slot-scope="scope">
                                    {{scope.row.type}}入库
                                </template>
                            </el-table-column>
                            <el-table-column prop="surplusNum" sortable label="剩余数量">
                                <template slot-scope="scope">
                                    {{scope.row.surplusNum}}{{scope.row.units}}
                                </template>
                            </el-table-column>
                            <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
                            <el-table-column label="操作" width="150" align="center">
                                <template slot-scope="scope">
                                    <el-button
                                        type="text"
                                        v-if="check"
                                        @click="handleView(scope.$index, scope.row)"
                                    >查看</el-button>
                                    <span v-if="scope.row.isRecall == 0">
			                    <span v-if="check1">
			                    <el-button
                                    type="text"
                                    @click="handleFrmLoss(scope.$index, scope.row)"
                                    v-if="scope.row.type == '原料'"
                                >报损</el-button>
			                    <el-button
                                    type="text"
                                    @click="handleNum(scope.$index, scope.row)"
                                    v-if="scope.row.type == '生产'"
                                >调整产量</el-button>
			                    </span>
			                    </span>
                                    <el-button
                                        v-if="scope.row.isRecall == 1"
                                        type="info"
                                        disabled
                                    >已召回</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize" @current-change="handleCurrentChange6" :total="total6" :current-page.sync="currentPage6" style="margin-top:20px"></el-pagination>
                    </el-row>
                </el-tab-pane>
                <el-tab-pane v-if='switchHeadTab =="生产系统"' label="配方颗粒(颗粒)" name="配方颗粒(颗粒)">
                    <el-row style="margin: 10px 0 20px 0">
                        <el-col :span="7">
                            <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="searchName4">
                                <i slot="prefix" class="el-input__icon el-icon-search"></i>
                                <el-button slot="append" @click="handleSearch4">搜索</el-button>
                            </el-input>
                        </el-col>
                        <router-link :to="{path:'/inventory/invenToryIndex'}"><el-button type="primary" v-if="check" style="float:right; margin-right: 10px">仓库管理</el-button></router-link>
                        <el-button style="float:right; margin-right: 10px" @click="download">导出</el-button>
                    </el-row>
                    <el-row>
                        <el-table
                            :data="tableData"
                            border
                            ref="multipleTable"
                            header-cell-class-name="table-header"
                        >
                            <el-table-column prop="breedName" sortable label="品名名称"></el-table-column>
                            <el-table-column prop="batch" sortable label="批次"></el-table-column>
                            <el-table-column prop="totalNum" sortable label="数量">
                                <template slot-scope="scope">
                                    {{scope.row.totalNum}}<span v-if="scope.row.totalNum != '' && scope.row.totalNum != null">{{scope.row.units}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="type" sortable label="入库类型">
                                <template slot-scope="scope">
                                    {{scope.row.type}}入库
                                </template>
                            </el-table-column>
                            <el-table-column prop="surplusNum" sortable label="剩余数量">
                                <template slot-scope="scope">
                                    {{scope.row.surplusNum}}{{scope.row.units}}
                                </template>
                            </el-table-column>
                            <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
                            <el-table-column label="操作" width="150" align="center">
                                <template slot-scope="scope">
                                    <el-button
                                        type="text"
                                        v-if="check"
                                        @click="handleView(scope.$index, scope.row)"
                                    >查看</el-button>
                                    <span v-if="scope.row.isRecall == 0">
                                <span v-if="check1">
                                <el-button
                                    type="text"
                                    @click="handleFrmLoss(scope.$index, scope.row)"
                                    v-if="scope.row.type == '原料'"
                                >报损</el-button>
                                <el-button
                                    type="text"
                                    @click="handleNum(scope.$index, scope.row)"
                                    v-if="scope.row.type == '生产'"
                                >调整产量</el-button>
                                </span>
                                </span>
                                    <el-button
                                        v-if="scope.row.isRecall == 1"
                                        type="info"
                                        disabled
                                    >已召回</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize4" @current-change="handleCurrentChange4" :total="total4" :current-page.sync="currentPage4" style="margin-top:20px"></el-pagination>
                    </el-row>
                </el-tab-pane>
                <el-tab-pane v-if='switchHeadTab =="生产系统"' label="配方颗粒" name="配方颗粒">
                    <el-row style="margin: 10px 0 20px 0">
                        <el-col :span="7">
                            <el-input placeholder="请输入关键词" style="width:300px" v-model.trim="searchName5">
                                <i slot="prefix" class="el-input__icon el-icon-search"></i>
                                <el-button slot="append" @click="handleSearch5">搜索</el-button>
                            </el-input>
                        </el-col>
                        <router-link :to="{path:'/inventory/invenToryIndex'}"><el-button type="primary" v-if="check" style="float:right; margin-right: 10px">仓库管理</el-button></router-link>
                        <el-button style="float:right; margin-right: 10px" @click="download">导出</el-button>
                    </el-row>
                    <el-row>
                        <el-table
                            :data="tableData"
                            border
                            ref="multipleTable"
                            header-cell-class-name="table-header"
                        >
                            <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                            <el-table-column prop="batch" sortable label="批次"></el-table-column>
                            <el-table-column prop="totalNum" sortable label="数量">
                                <template slot-scope="scope">
                                    {{scope.row.totalNum}}<span v-if="scope.row.totalNum != '' && scope.row.totalNum != null">{{scope.row.units}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="type" sortable label="入库类型">
                                <template slot-scope="scope">
                                    {{scope.row.type}}入库
                                </template>
                            </el-table-column>
                            <el-table-column prop="surplusNum" sortable label="剩余数量">
                                <template slot-scope="scope">
                                    {{scope.row.totalNum}}<span v-if="scope.row.totalNum != '' && scope.row.totalNum != null">{{scope.row.units}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="qualityStandard" sortable label="质量标准"></el-table-column>
                            <el-table-column label="操作" width="150" align="center">
                                <template slot-scope="scope">
                                    <el-button
                                        type="text"
                                        @click="handleView(scope.$index, scope.row)"
                                    >查看</el-button>
                                    <span v-if="scope.row.isRecall == 0">
                                <span v-if="check1">
                                <el-button
                                    type="text"
                                    @click="handleFrmLoss(scope.$index, scope.row)"
                                    v-if="scope.row.type == '原料'"
                                >报损</el-button>
                                <el-button
                                    type="text"
                                    @click="handleNum(scope.$index, scope.row)"
                                    v-if="scope.row.type == '生产'"
                                >调整产量</el-button>
                                </span>
                                </span>
                                    <el-button
                                        v-if="scope.row.isRecall == 1"
                                        type="info"
                                        disabled
                                    >已召回</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize5" @current-change="handleCurrentChange5" :total="total5" :current-page.sync="currentPage5" style="margin-top:20px"></el-pagination>
                    </el-row>
                </el-tab-pane>
        </el-tabs>
        <el-dialog title="报损" :visible.sync="dialogFormVisible">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
                <el-row>
                    <el-col :span="16">
                        <el-form-item label="报损日期：" label-width="120px">
                            <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd" v-model.trim="ruleForm.time" style="width: 300px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="报损数量：" prop="lossNum" label-width="120px">
                            <el-input v-model.number="ruleForm.lossNum" type="number" @change="changeNum" style="width:300px">
                                <template slot="append">
                                    {{ruleForm.lossUnits}}
                                </template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="报损人：" prop="name" label-width="120px">
                             <el-input v-model="ruleForm.name"  :disabled="disabled" style="width:300px"></el-input>

                        </el-form-item>
                        <el-form-item label="报损原因：" label-width="120px">
                            <el-input type="textarea" v-model="ruleForm.lossExplain" style="width:300px"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
            </div>
        </el-dialog>

        <el-dialog title="调整产量" :visible.sync="dialogFormVisible1">
            <el-form :model="ruleForm1" :rules="rules1" ref="ruleForm1">
                <el-row>
                    <el-col :span="16">
                        <el-form-item label="调整日期：" label-width="120px">
                            <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd" v-model="ruleForm1.time" style="width: 300px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="实际产量：" prop="newNumber" label-width="120px">
                            <el-input v-model.trim="ruleForm1.newNumber" style="width:300px">
                                <template slot="append">
                                    {{ruleForm1.units}}
                                </template>
                            </el-input>
                        </el-form-item>
                        <el-form-item label="操作人：" prop="relevantUser" label-width="120px">
                            <el-select v-model="ruleForm1.relevantUser" filterable placeholder="请选择" value-key="id" @change="changeRelevant1" style="width:300px">
                                <el-option
                                    v-for="item in userList"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item"
                                >
                                {{item.name}}
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible1 = false">取 消</el-button>
                <el-button type="primary" @click="submitForm1('ruleForm1')">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import axios from 'axios'
    import {warehouse_findList,user_findAll,loss_save,manufacture_findById,manufacture_adjust, warehouse_export} from "@/request/api";
    import { mapState } from 'vuex';
    export default {
        data() {
            return {
                tableDataOfMedicinalHerb:[],
                tableDataOfMedicinalHerbSemiFormedProducts:[],
                searchMedicalHerb:'',
                searchMedicalHerbSemiFormedProducts:'',
                medicalHerbPage:1,
                medicalHerbPageSize:10,
                medicalHerbTotal:0,

                medicalHerbPageSemiFormedProducts:1,
                medicalHerbPageSizeSemiFormedProducts:10,
                medicalHerbTotalSemiFormedProducts:0,

                disabled:true,
                check1:true,
                check:true,
                dialogFormVisible: false,
                dialogFormVisible1: false,
                activeName: '中药材',
                materialType: '中药材',
                searchName1: '',
                searchName2: '',
                searchName3: '',
                searchName4: '',
                searchName5: '',
				searchName6: '',
                tableData: [],
                total1: 0,
                currentPage1:1,
				pagesize:10,
                pagesize1:10,
                total2: 0,
                currentPage2:1,
                pagesize2:10,
                total3: 0,
                currentPage3:1,
                pagesize3:10,
                total4: 0,
                currentPage4:1,
                pagesize4:10,
                total5: 0,
                currentPage5:1,
                pagesize5:10,
				total6: 0,
				currentPage6:1,
                ruleForm: {
                    name: '',
                    lossNum: '',
                    lossUnits: '',
                    lossExplain: ''
                },
                rules:{
                    name: [
                        { required: true, message: '不能为空', trigger: 'change' }
                    ],
                    lossNum: [
                        { required: true, message: '不能为空', trigger: 'change' }
                    ]
                },
                userList: [],
                surplusNum: 0,
                ruleForm1: {
                    time: '',
                    relevantUser: '',
                    relevantUserIds: '',
                    newNumber: '',
                    units: '',
                },
                rules1:{
                    relevantUser: [
                        { required: true, message: '不能为空', trigger: 'change' }
                    ],
                    newNumber: [
                        { required: true, message: '不能为空', trigger: 'blur' }
                    ]
                },
                pageNum: ''
            };
        },
        destroyed: function () {
            this.$store.commit("setStorName","")
        },
        created(){
            var data = JSON.stringify(this.$store.state.kc)
            var b = '调整库存'
            var a = '仓库管理'
            if(data.indexOf(b) != -1){
                this.check1 = true
            }else{
                this.check1 = false
            }

            if(data.indexOf(a) != -1){
                this.check = true
            }else{
                this.check = false
            }
        },
        mounted(){
            this.ruleForm.userId = this.$store.state.userid
            this.ruleForm.name = this.$store.state.user
            if(this.$store.state.storName == '中药材'){
                this.activeName = '中药材'
                this.init1()
            } else if(this.$store.state.storName == '辅料'){
                this.activeName = '辅料'
                this.init2()
            } else if(this.$store.state.storName == '提取饮片'){
                this.activeName = '提取饮片'
                this.init3()
            } else if(this.$store.state.storName == '配方颗粒(颗粒)'){
                this.activeName = '配方颗粒(颗粒)'
                this.init4()
            } else if(this.$store.state.storName == '配方颗粒'){
                this.activeName = '配方颗粒'
                this.init5()
            }else if(this.$store.state.storName == '配方颗粒(浸膏粉)'){
                this.activeName = '配方颗粒(浸膏粉)'
                this.init6()
            }else if(this.$store.state.storName == '中药饮片'){
                this.activeName = '中药饮片'
                this.getMedicalHerb();
            }else if(this.$store.state.storName == '中药饮片(半成品)'){
                this.activeName = '中药饮片(半成品)'
                this.getMedicalHerbSemiFormedProducts();
            }else{
                this.activeName = '中药材'
                this.init1()
            }

        },
        computed:{
            ...mapState(['switchHeadTab'])
        },
        methods: {
            // download(){
            //     warehouse_export({
            //         materialType: '中药材'
            //     }).then(res => {
            //         console.log('ok')
            //         this.downloadFile(res, '库存.xls')
            //     }).catch(err => {
            //         console.log(err)
            //     })
            // },
            async getMedicalHerb(){
               const res = await warehouse_findList({
                    materialType:'中药饮片',
                    searchName: this.searchMedicalHerb,
                    page:this.medicalHerbPage,
                    pageSize:this.medicalHerbPageSize,
                })
               try{
                   if(res && res.code == 200){
                        this.tableDataOfMedicinalHerb = res.data.rows
                        this.medicalHerbTotal = res.data.total
                   }else{
                       this.$message.error(res.data.msg)
                   }
               }catch (e) {
                   this.$message.error(e)
                   throw e
               }
            },
            async getMedicalHerbSemiFormedProducts(){
                const res = await warehouse_findList({
                    materialType:'中药饮片(半成品)',
                    searchName: this.searchMedicalHerbSemiFormedProducts,
                    page:this.medicalHerbPageSemiFormedProducts,
                    pageSize:this.medicalHerbPageSizeSemiFormedProducts,
                })
                try{
                    if(res && res.code == 200){
                        this.tableDataOfMedicinalHerbSemiFormedProducts = res.data.rows
                        this.medicalHerbTotalSemiFormedProducts = res.data.total
                    }else{
                        this.$message.error(res.data.msg)
                    }
                }catch (e) {
                    this.$message.error(e)
                    throw e
                }
            },
            download(){
                axios({
                    method: 'POST',
                    url: '/warehouse/export',
                    responseType: 'blob',
                    data:{
                        materialType: this.activeName
                    }
                }).then(res=>{
                    console.log(this.$downloadFile)
                    this.$downloadFile.downloadFile(res, this.activeName + '.xls')
                }).catch(err=>{
                    console.log(err)
                })
            },
            // 调用接口
            init1(){
                warehouse_findList({
                  materialType: '中药材',
                  searchName: this.searchName1,
                  page: this.currentPage1,
                }).then((res) =>{
                  this.tableData = res.data.rows
                  this.total1 = res.data.total
                  for (let i = 0; i < this.tableData.length; i++) {
                      if(this.tableData[i].qualityStandard){
                          this.tableData[i].qualityStandard = this.tableData[i].qualityStandard.substring(0, 5) + "...."
                      }
                  }
                })
            },
            init2(){
                warehouse_findList({
                  materialType: '辅料',
                  searchName: this.searchName2,
                  page: this.currentPage2,
                }).then((res) =>{
                  this.tableData = res.data.rows
                  this.total2 = res.data.total
                   for (let i = 0; i < this.tableData.length; i++) {
                      if(this.tableData[i].qualityStandard){
                          this.tableData[i].qualityStandard = this.tableData[i].qualityStandard.substring(0, 5) + "...."
                      }
                  }
                })
            },
            init3(){
                warehouse_findList({
                  materialType: '提取饮片',
                  searchName: this.searchName3,
                  page: this.currentPage3,
                }).then((res) =>{
                  this.tableData = res.data.rows
                  this.total3 = res.data.total
                   for (let i = 0; i < this.tableData.length; i++) {
                      if(this.tableData[i].qualityStandard){
                          this.tableData[i].qualityStandard = this.tableData[i].qualityStandard.substring(0, 5) + "...."
                      }
                  }
                })
            },
            init4(){
                warehouse_findList({
                  type: '生产',
                  materialType: '配方颗粒(颗粒)',
                  searchName: this.searchName4,
                  page: this.currentPage4,
                }).then((res) =>{
                  this.tableData = res.data.rows
                  this.total4 = res.data.total
                   for (let i = 0; i < this.tableData.length; i++) {
                      if(this.tableData[i].qualityStandard){
                          this.tableData[i].qualityStandard = this.tableData[i].qualityStandard.substring(0, 5) + "...."
                      }
                  }
                })
            },
            init5(){
                warehouse_findList({
                  type: '包装',
                  materialType: '配方颗粒',
                  searchName: this.searchName5,
                  page: this.currentPage5,
                }).then((res) =>{
                  this.tableData = res.data.rows
                  this.total5 = res.data.total
                   for (let i = 0; i < this.tableData.length; i++) {
                      if(this.tableData[i].qualityStandard){
                          this.tableData[i].qualityStandard = this.tableData[i].qualityStandard.substring(0, 5) + "...."
                      }
                  }
                })
            },
			init6(){
				warehouse_findList({
				  materialType: '配方颗粒(浸膏粉)',
				  searchName: this.searchName6,
				  page: this.currentPage6,
				}).then((res) =>{
				  this.tableData = res.data.rows
				  this.total6 = res.data.total
                   for (let i = 0; i < this.tableData.length; i++) {
                      if(this.tableData[i].qualityStandard){
                          this.tableData[i].qualityStandard = this.tableData[i].qualityStandard.substring(0, 5) + "...."
                      }
                  }
				})
			},
            // tabs
            handleClick(tab, event) {
                this.materialType = tab.label
                this.searchMedicalHerb = this.materialType != '中药饮片'? '':this.searchMedicalHerb
                if (this.materialType == '中药材') {
                    this.init1()
                } else if(this.materialType == '辅料') {
                    this.init2()
                } else if(this.materialType == '提取饮片'){
                    this.init3()
                } else if(this.materialType == '配方颗粒(颗粒)'){
                    this.init4()
                } else if(this.materialType == '配方颗粒'){
                    this.init5()
                }else if(this.materialType == '配方颗粒(浸膏粉)'){
                    this.init6()
                }else if(this.materialType == '中药饮片'){
                    this.getMedicalHerb();
                }else if(this.materialType == '中药饮片(半成品)'){
                    this.getMedicalHerbSemiFormedProducts();
                }
            },
            // 用户列表
            userListFun() {
                user_findAll('').then((res)=>{
                    this.userList = res.data
                })
            },
            // 选择报损相关人
            // changeRelevant(ele){
            //     this.ruleForm.userId = ele.id
            //     this.ruleForm.name = ele.name
            // },
            // 报损数量
            changeNum(ele){
                if (ele <= 0) {
                    this.$notify.error({
                        title: '提示',
                        message: '报损数量不能为零或负数！',
                        showClose: false,
                        duration:2000
                    });
                    return this.ruleForm.lossNum = 0
                }
                if (ele > this.surplusNum) {
                    this.$notify.error({
                        title: '提示',
                        message: '报损数量不能大于剩余量！',
                        showClose: false,
                        duration:2000
                    });
                    return this.ruleForm.lossNum = 0
                }
            },
            //报损
            handleFrmLoss(index,row){
                this.dialogFormVisible = true
                this.userListFun();
                this.ruleForm.materialId = row.id
                this.ruleForm.lossUnits = row.units
                this.surplusNum = parseInt(row.surplusNum)
            },
            // 提交报损
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        loss_save(this.ruleForm).then((res) =>{
                            this.ruleForm = {}
                            this.$notify({
                                title: '提示',
                                message: '保存成功',
                                type: 'success',
                                duration:1000
                            });
                            this.dialogFormVisible = false
                            if (this.materialType == '中药材') {
                                this.init1()
                            } else if(this.materialType == '辅料') {
                                this.init2()
                            } else if(this.materialType == '提取饮片'){
                                this.init3()
                            } else if(this.materialType == '配方颗粒(颗粒)'){
                                this.init4()
                            } else if(this.materialType == '配方颗粒'){
                                this.init5()
                            }else if(this.materialType == '配方颗粒(浸膏粉)'){
                                this.init6()
                            }else if(this.materialType = '中药饮片'){
                                this.getMedicalHerb();
                            }
                        })
                    } else {
                        return false;
                    }
                })
            },
            // 查看
            handleView(index,row){
                if (row.type == '原料') {
                    this.$router.push({
                        path: '/materialCheck/viewMaterialCheck',
                        query: { id: row.id }
                    });
                } else if (row.type == '生产') {
                    this.$router.push({
                        path: '/production/viewProduction',
                        query: { id: row.id }
                    });
                } else if (row.type == '包装') {
                    this.$router.push({
                        path: '/packing/viewPacking',
                        query: { id: row.id }
                    });
                }
            },
            // 调整产量
            handleNum(index,row){
                this.dialogFormVisible1 = true
				this.ruleForm1.newNumber = ""
				this.ruleForm1.time = ""
                this.userListFun();
                manufacture_findById(row.id).then((res) =>{
                    this.ruleForm1.id = res.data.id
                    this.ruleForm1.units = res.data.units
                    this.ruleForm1.surplusNumber = res.data.surplusNumber
                    // this.ruleForm1 = res.data
                    // this.ruleForm1.relevantUser = res.data.relevantUsers
                })
            },
            // 选择调整产量相关人
            changeRelevant1(ele){
                this.ruleForm1.relevantUserId = ele.id
                this.ruleForm1.relevantUser = ele.name
            },
            // 提交产量
            submitForm1(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        // console.log(typeof this.ruleForm.userNumber)
                        if (parseInt(this.ruleForm1.newNumber) > parseInt(this.ruleForm1.surplusNumber)) {
                            var parm = {
                                relevanceId: this.ruleForm1.id,
                                time: this.ruleForm1.time,
                                relevantUser: this.ruleForm1.relevantUse,
                                relevantUserId: this.ruleForm1.relevantUserId,
                                newNumber: this.ruleForm1.newNumber,
                                units: this.ruleForm1.units,
                            }
                            manufacture_adjust(parm).then((res) => {
                                this.$notify({
                                    title: '提示',
                                    message: '添加成功',
                                    type: 'success',
                                    duration:1000
                                });
                                this.dialogFormVisible1 = false
                                if (this.materialType == '提取饮片') {
                                    this.init1()
                                } else if(this.materialType == '辅料') {
                                    this.init2()
                                } else if(this.materialType == '提取饮片'){
                                    this.init3()
                                } else if(this.materialType == '配方颗粒(颗粒)'){
                                    this.init4()
                                } else if(this.materialType == '配方颗粒'){
                                    this.init5()
                                }else if(this.materialType = '中药饮片'){
                                    this.getMedicalHerb();
                                } else if(this.materialType == '配方颗粒(浸膏粉)'){
								    this.init6()
								}
                            })
                        } else{
                            this.$notify.error({
                                title: '提示',
                                message: '实际产量不能小于剩余量'+this.ruleForm1.surplusNumber+'',
                                showClose: false,
                                duration:3000
                            });
                        }
                    } else {
                        return false;
                    }
                })
            },
            // 搜索
            handleSearch1() {
                this.currentPage1 = 1
                this.init1()
            },
            handleCurrentChange1(val){
                this.currentPage1 = val
                this.init1()
            },
            handleSearch2() {
                this.currentPage2 = 1
                this.init2()
            },
            handleCurrentChange2(val){
                this.currentPage2 = val
                this.init2()
            },
            handleSearch3() {
                this.currentPage3 = 1
                this.init3()
            },
            handleCurrentChange3(val){
                this.currentPage3 = val
                this.init3()
            },
            handleSearch4() {
                this.currentPage4 = 1
                this.init4()
            },
            handleCurrentChange4(val){
                this.currentPage4 = val
                this.init4()
            },
            handleSearch5() {
                this.currentPage5 = 1
                this.init5()
            },
            handleCurrentChange5(val){
                this.currentPage5 = val
                this.init5()
            },
			handleSearch6() {
			    this.currentPage6 = 1
			    this.init6()
			},
			handleCurrentChange6(val){
			    this.currentPage6 = val
			    this.init6()
			},
        }
    }
</script>

<style scoped>
.el-pagination{
    text-align: center;
}
.el-col{
    margin-bottom: 0;
}
.el-select .el-input {
width: 130px;
}
.input-with-select .el-input-group__prepend {
background-color: #fff;
}
.el-input--small .el-input__inner{
    border-radius: 5px 0 0 5px !important;
    border-right: none;
}
</style>
